﻿using Com.Aote.ObjectTools;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Com.Aote.Pages
{
	public partial class 翼支付对账 : UserControl
	{
		public 翼支付对账()
		{
			InitializeComponent();
        }

        private void dansearchbutton_Click(object sender, RoutedEventArgs e)
        {
            SearchObject so = daninfosearch.DataContext as SearchObject;
            so.Search();
            PagedList list = daninfos.ItemsSource as PagedList;
            list.LoadOnPathChanged = false;
            String SumHQL = @"
            select id, cast(CONVERT(varchar(10), f_deliverydate, 120) as varchar(10)) f_deliverydate , f_grossproceeds, f_userid, trans_sn, user_id, f_banksn, sale_id, total_fee,cast(CONVERT(nvarchar(10), bank_date, 120) as varchar(10)) bank_date, 
            case 
								when f_grossproceeds=total_fee and f_payfeevalid='有效' then '对账成功' 
								when f_grossproceeds=total_fee and f_payfeevalid='无效' then '翼支付冲正失败，需燃气公司手工记帐' 
								when f_userid is null and f_payfeevalid='无效' then '翼支付冲正成功，无效缴费' 
								when f_userid is null and f_payfeevalid='有效' then '燃气公司单边账' 
								when user_id is null then '翼支付单边账' 
								else '对账金额错误' 
						end msg, f_payfeevalid from 
            (select id, f_deliverydate, f_grossproceeds, f_userid, REPLACE(f_banksn,' ','') f_banksn, f_payfeevalid from t_sellinggas where 
            f_deliverydate>=substring('{0}',1,10) and  f_deliverydate<=substring('{1}',1,10) and f_bankname='{2}') t1
            full outer join
            (
            select REPLACE(trans_sn,' ','') trans_sn, user_id, sale_id, total_fee,bank_date  from t_bank_payment where BANK_DATE>=substring('{0}',1,10) and BANK_DATE<=substring('{1}',1,10)  and f_bankname='{2}'
            ) t2
            on t1.f_banksn=t2.trans_sn		 		
            ";
            Object s1 = so.GetPropertyValue("f_yytdate1");
            Object s2 = so.GetPropertyValue("f_yytdate2");
            Object s3 = so.GetPropertyValue("f_bankname");
            SumHQL = String.Format(SumHQL, s1,s2,s3);
            list.SumHQL = SumHQL;
            list.HQL = SumHQL + " order by f_userid, user_id";
            list.Load();
        }
	}
}